<template>
  <div class="app-container">
    <el-dialog
      title="批量导入"
      :visible.sync="visible"
      width="800px"
      :before-close="handleClose"
      append-to-body
    >
      <exportXlsx
        ref="exportXlsx"
        :title="title"
        :upurl="upurl"
        :downurl="downurl"
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancle">取 消</el-button>
        <el-button type="primary" @click="sub">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import exportXlsx from "@/components/FileUpload/export";
export default {
  name: "upload",
  components: {
    exportXlsx,
  },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    type: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      upurl: "",
      downurl: "",
      title: "",
    };
  },
  watch: {
    visible: {
      handler(val) {
        if (val) {
          if (this.type == "msg") {
            this.title = "图书信息导入模板";
            this.upurl = "/virlib-admin/ctrl/file";
            this.downurl = "";
          } else {
            this.title = "资产信息导入模板";
            this.upurl = "/virlib-admin/asset/file";
            this.downurl = "";
          }
        }
      },
      deep: false,
      immediate: true,
    },
  },
  methods: {
    cancle() {
      this.handleClose(false);
    },
    sub() {
      this.$refs.exportXlsx.sub();
      setTimeout(() => {
        this.handleClose(true);
      }, 500);
    },
    handleClose(status) {
      this.$emit("update:visible", false);
      this.$emit("close", status === true ? status : false);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
